﻿<?php
error_reporting(E_ALL^E_NOTICE);
$title="系统安装";
include ('include/head.php');
echo '<div class="header"><ul class="nav nav-pills pull-right" role="tablist"><li role="presentation" class="active"><a href="index.php">首页</a></li><li role="presentation"><a href="admin/index.php">后台管理</a></li><li role="presentation"><a href="install.php">安装</a></li></ul><h3 class="text-muted" align="left">系统安装</h3></div><hr>';  
if (file_exists("./include/data/install.lock")){
	echo '已安装，请删除install.lock';
}else{

if(!isset($_GET['do'])){
	echo '<h3 class="form-signin-heading">函数检测</h3>';
	function fun_c($fun){
		$result=function_exists($fun)?' <font color="green">支持</font><br/>':' <font color="red">不支持</font><br/>';
		echo $fun.$result;
	}
		fun_c("curl_init");
		fun_c("file_get_contents");
		fun_c("file_put_contents");
		fun_c("getimagesize");
		echo '<a href="install.php?do=2" class="btn btn-primary btn-block">下一步</a><br>';
}

if($_GET['do'] == "2"){
if(isset($_POST['host'])&&isset($_POST['dbpwd'])){
$host = $_POST['host'];
$dbuser = $_POST['dbuser'];
$dbpwd = $_POST['dbpwd'];
$dbname = $_POST['dbname'];
$aname = $_POST['aname'];
$apwd = md5($_POST['apwd']);
$config='<?php
if(!defined(\'IN_WSHUO\')) exit();
//MYSQL主机
$host = "'.$host.'";
//MYSQL用户
$dbuser = "'.$dbuser.'";
//用户密码
$dbpwd = "'.$dbpwd.'";
//数据库名
$dbname = "'.$dbname.'";

?>';
$aconn='<?php
if(!defined(\'IN_WADMIN\')) exit();
$w_adminname=\''.$aname.'\';
$w_adminpwd=\''.$apwd .'\';
?>';

file_put_contents('./include/data/config.php', $config) or die("保存出错，可能是include目录不可写!");
file_put_contents('./admin/aconn.php', $aconn) or die("保存出错，可能是admin目录不可写!");
echo '配置完成<br /><a href="install.php?do=3" class="btn btn-primary btn-block">下一步</a><br>';
}else{
	echo '<h3 class="form-signin-heading">系统配置</h3>
		<form action="install.php?do=2" class="form-sign" method="post">
		数据库地址:<br><input type="text" class="form-control" name="host" value="localhost"><br>
		数据库用户:<br><input type="text" class="form-control" name="dbuser" value="root"><br>
		数据库密码:<br><input type="text" class="form-control" name="dbpwd" value="root"><br>
		数据库名:<br><input type="text" class="form-control" name="dbname" value="wshuo"><br>
		管理员名:<br><input type="text" class="form-control" name="aname" value="admin"><br>
		管理员密码:<br><input type="text" class="form-control" name="apwd" value="admin"><br>
		<input type="submit" class="btn btn-primary btn-block" name="submit" value="保存">
		</form>';

}
}

if($_GET['do'] == "3"){
	require_once './include/common.php';
	$sq = file_get_contents("wshuo.txt");
	$sq = str_replace('\\', '', $sq);
	$sql = explode(';', $sq);
	$snum = count($sql)-1;
	for ($i = 0; $i<$snum; $i++) {
		$count = $db->exec($sql[$i]);
		echo ($i+1).'执行条语句成功<br>';
	}
	echo '数据库导入成功！<br /><a href="install.php?do=lock" class="btn btn-primary btn-block">点击继续</a>';
}

if ($_GET['do']== 'lock') {
	
	file_put_contents('./include/data/install.lock', "wshuo") or die("保存出错，可能是include目录不可写!");

	echo "恭喜你安装成功<a href='admin/index.php'>进入后台</a>";
}

}
	
include ('include/foot.php');
exit;